// 这个模块是处理权限的模块, 路由规则this.$route.optios.routes这个数据不是响应式的
import { constantRoutes, asyncRoutes } from '@/router'
const state = {
  routes: constantRoutes
}
const mutations = {
  // 设置路由的mutation
  setRoutes(state, asyncRoutes) {
    state.routes = [...constantRoutes, ...asyncRoutes, { path: '*', redirect: '/404', hidden: true }]
  }
}
// context.commit('setRoutes', [4])
const actions = {
  // 其实这个action不抽离也可以, 直接放在导航守卫也行
  filterRoutes(context, menus) {
    const res =	asyncRoutes.filter(item => menus.includes(item.children[0].name))
    context.commit('setRoutes', res)
    return res // 需要添加返回值, 供导航守卫调用addRoutes
  }
}
const getters = {}
export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
